from pprint import pprint

from django.shortcuts import render
from django.views import View

from apps.company.models import Company
from apps.index.models import JobCategory
from apps.index.utils import get_categories
from apps.users.models import User


class IndexView(View):
    def get(self, request):
        ruser = request.user
        try:
            user = User.objects.get(id=ruser.id)
        except:
            user = None
        try:
            company = Company.objects.get(user_id=user.id)
        except:
            company = None
        # 分类
        channel_dict = get_categories()

        #
        category = JobCategory.objects.filter()

        context = {
            'user': user,  # 用户
            'company': company,
            'channels': channel_dict,  # 分类

        }
        return render(request, 'index.html', context)


def page_not_found(request, **kwargs):
    return render(request, "common/404.html")
